/**
 * 打印线程的状态
 */
public class ThreadExample4 {
    public static void main(String[] args) {
        Thread thread = new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                try {
                    System.out.println(Thread.currentThread().getName() + " : I am alive!");
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

            try {
                System.out.println(Thread.currentThread().getName() + " : I am leave in just one second!!");
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }, "I am iron man~");

        System.out.println(thread.getName()
                + ": ID: " + thread.getId());
        System.out.println(thread.getName()
                + ": 名称: " + thread.getName());
        System.out.println(thread.getName()
                + ": 状态: " + thread.getState());
        System.out.println(thread.getName()
                + ": 优先级: " + thread.getPriority());
        System.out.println(thread.getName()
                + ": 后台线程: " + thread.isDaemon());
        System.out.println(thread.getName()
                + ": 活着: " + thread.isAlive());
        System.out.println(thread.getName()
                + ": 被中断: " + thread.isInterrupted());
        System.out.println("*******************************");

        thread.start();

        System.out.println(thread.getName()
                + ": 状态: " + thread.getState());
        System.out.println(thread.getName()
                + ": 活着: " + thread.isAlive());

        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println(thread.getName()
                + ": 状态: " + thread.getState());
        System.out.println(thread.getName()
                + ": 活着: " + thread.isAlive());

        try {
            thread.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println(thread.getName()
                + ": 状态: " + thread.getState());
        System.out.println(thread.getName()
                + ": 活着: " + thread.isAlive());
    }
}

/**
 * I am tron man~: ID: 24
 * I am tron man~: 名称: I am tron man~
 * I am tron man~: 状态: NEW
 * I am tron man~: 优先级: 5
 * I am tron man~: 后台线程: false
 * I am tron man~: 活着: false
 * I am tron man~: 被中断: false
 * *******************************
 * I am tron man~: 状态: RUNNABLE
 * I am tron man~ : I am alive!
 * I am tron man~: 活着: true
 * I am tron man~ : I am alive!
 * I am tron man~ : I am alive!
 * I am tron man~ : I am alive!
 * I am tron man~: 状态: TIMED_WAITING
 * I am tron man~: 活着: true
 * I am tron man~ : I am alive!
 * I am tron man~ : I am alive!
 * I am tron man~ : I am alive!
 * I am tron man~ : I am alive!
 * I am tron man~ : I am alive!
 * I am tron man~ : I am alive!
 * I am tron man~ : I am leave in just one second!!
 * I am tron man~: 状态: TERMINATED
 * I am tron man~: 活着: false
 */
